﻿using System;
using System.Collections.Generic;
using WickedFlame.Core;
using WickedFlame.Core.Shapes;

namespace WickedFlame.Util.Actions
{
    public class MergeLayersAction
    {
        public void DoAction(DrawingCanvas canvas)
        {
            if (canvas.Layers.Count > 1 && canvas.SelectedLayerIndex < canvas.Layers.Count - 1)
            {
                //foreach (VectorShape shape in canvas.SelectedLayer.ShapeList)
                while (canvas.SelectedLayer.ShapeList.Count > 0)
                {
                    //VectorShape shape = canvas.SelectedLayer.ShapeList.TopShape;
                    var shape = canvas.SelectedLayer.ShapeList[0] as VectorShape;
                    canvas.SelectedLayer.RemoveShape(shape);

                    canvas.Layers[canvas.SelectedLayerIndex + 1].AddShape(shape);
                    //canvas.Layers[canvas.SelectedLayerIndex - 1].AddShape(shape);
                }

                canvas.RemoveLayer();
            }
        }
    }
}
